package com.lonty.intelligence.controller;

import com.lonty.intelligence.api.Result;
import com.lonty.intelligence.api.ResultCode;
import com.lonty.intelligence.service.SpotService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * @Author 陈璇
 * @Date 2020/7/9 11:10
 * @Version 1.0
 */
@RestController
@RequestMapping("app/spot")
@Validated
@Api(tags = "点击接口", produces = "application/json")
public class SpotController {

    @Resource
    private SpotService spotService;

    @ApiOperation(value = "保存点击", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名字",dataType = "string", paramType = "query", required = true)
    })
    @PostMapping("saveSpot")
    public Result saveSpot(String name){
        if(spotService.saveSpot(name)){
            return Result.builder().build();
        }
        return Result.builder(ResultCode.OPERATION_ERROR).build();
    }

    @ApiOperation(value = "获取点击", httpMethod = "GET")
    @GetMapping("getSpotList")
    public Result getSpotList(){
        return Result.builder()
                .data(spotService.getSpotList())
                .build();
    }

    @ApiOperation(value = "修改点击数", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id",dataType = "string", paramType = "query", required = true)
    })
    @PostMapping("modifyNum")
    public Result modifyNum(String id){
        if(spotService.modifyNum(id)){
            return Result.builder().build();
        }
        return Result.builder(ResultCode.OPERATION_ERROR).build();
    }

}
